using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;

namespace Waaahsabi.Controls.TheGame
{
	public class TimedDistortEffect : ShaderEffect
	{
		public static readonly DependencyProperty InputProperty = RegisterPixelShaderSamplerProperty("Input",
		                                                                                             typeof (
		                                                                                             	TimedDistortEffect), 0);

		public static readonly DependencyProperty WaveStrengthProperty = DependencyProperty.Register("WaveStrength",
		                                                                                             typeof (double),
		                                                                                             typeof (
		                                                                                             	TimedDistortEffect),
		                                                                                             new PropertyMetadata(
		                                                                                             	((double) (0)),
		                                                                                             	PixelShaderConstantCallback
		                                                                                             		(0)));

		public static readonly DependencyProperty FrequencyProperty = DependencyProperty.Register("Frequency", typeof (double),
		                                                                                          typeof (TimedDistortEffect),
		                                                                                          new PropertyMetadata(
		                                                                                          	((double) (3)),
		                                                                                          	PixelShaderConstantCallback
		                                                                                          		(1)));

		public static readonly DependencyProperty ShiftProperty = DependencyProperty.Register("Shift", typeof (double),
		                                                                                      typeof (TimedDistortEffect),
		                                                                                      new PropertyMetadata(
		                                                                                      	((double) (0)),
		                                                                                      	PixelShaderConstantCallback(2)));

		public TimedDistortEffect()
		{
			PixelShader pixelShader = new PixelShader();
			pixelShader.UriSource = new Uri("/Waaahsabi.Controls.TheGame;component/timedDistort.ps", UriKind.Relative);
			PixelShader = pixelShader;

			UpdateShaderValue(InputProperty);
			UpdateShaderValue(WaveStrengthProperty);
			UpdateShaderValue(FrequencyProperty);
			UpdateShaderValue(ShiftProperty);
		}

		public Brush Input
		{
			get { return ((Brush) (GetValue(InputProperty))); }
			set { SetValue(InputProperty, value); }
		}

		/// <summary>
		///   defines the strength of the distortion
		/// </summary>
		public double WaveStrength
		{
			get { return ((double) (GetValue(WaveStrengthProperty))); }
			set { SetValue(WaveStrengthProperty, value); }
		}

		/// <summary>
		///   defines the frequency of the distortion
		/// </summary>
		public double Frequency
		{
			get { return ((double) (GetValue(FrequencyProperty))); }
			set { SetValue(FrequencyProperty, value); }
		}

		/// <summary>
		///   defines the shift of the distortion
		/// </summary>
		public double Shift
		{
			get { return ((double) (GetValue(ShiftProperty))); }
			set { SetValue(ShiftProperty, value); }
		}
	}
}